Skip to content

fix: drop unused wp-admin/includes/media.php require - #13

Merged
nolderoos merged 2 commits into
mainfrom
fix/core-loading-files
May 14, 2026
Merged

nolderoos merged 2 commits into
mainfrom
fix/core-loading-files

Conversation

@nolderoos

@nolderoos nolderoos commented May 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #12

What

Removes the unused require_once ABSPATH . 'wp-admin/includes/media.php'; from OpenTrust_IO::sideload_bundled_media().

Why

wp.org review round 1, issue 3: admin includes are allowed only if a function from the file is used immediately after. file.php (used: wp_unique_filename()) and image.php (used: wp_generate_attachment_metadata()) stay. media.php had no consumer — the method writes attachments directly so SVG and similar types survive import.

Summary by CodeRabbit

  • Refactor
    • Improved bundled media import handling to enhance compatibility with media processing and post-upload workflows.
  • Documentation
    • Updated translation template metadata and source references for import-related messages.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 12, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dd429687-a8b4-41bf-8fbd-92c888b7a590

📥 Commits

Reviewing files that changed from the base of the PR and between 0f82f73 and cb748d1.

📒 Files selected for processing (1)
  • languages/opentrust.pot
✅ Files skipped from review due to trivial changes (1)
  • languages/opentrust.pot

📝 Walkthrough

Walkthrough

Change the admin include in OpenTrust_IO::sideload_bundled_media() from wp-admin/includes/media.php to wp-admin/includes/image.php. Also update languages/opentrust.pot metadata timestamp and adjust source-reference line numbers for several import-related messages.

Changes

Bundled Media Importer & i18n

Layer / File(s) Summary
Replace admin include in sideload_bundled_media
includes/class-opentrust-io.php
require_once ABSPATH . 'wp-admin/includes/media.php' was replaced with require_once ABSPATH . 'wp-admin/includes/image.php' prior to attachment metadata generation in sideload_bundled_media().
Update POT metadata and source references
languages/opentrust.pot
POT-Creation-Date updated and source-reference line numbers for several import-related msgid entries adjusted to reflect new extraction positions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A tiny hop, a tidy swap,
One require drops, the rest hop-stop.
Timestamps nudged, the lines align,
The importer hums, the strings refine.
A soft-field fix — a carrot, fine.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing an unused wp-admin/includes/media.php require statement from the code.
Linked Issues check ✅ Passed The PR successfully addresses issue #12 by removing the unused media.php require [#12], satisfying the WordPress.org reviewer requirement to remove core admin includes that have no immediate function usage.
Out of Scope Changes check ✅ Passed All changes are directly in scope: the removal of the unused require statement from class-opentrust-io.php and corresponding line number updates in the translation template file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/core-loading-files

Comment @coderabbitai help to get the list of available commands and usage tips.

@nolderoos

Copy link
Copy Markdown
Collaborator Author

Claude Code review

Verdict: Approve.

This is the minimal correct fix for round-2 issue #3. One deleted line, zero behavioural change, matches the analysis in wporg-review/03-core-loading-files/analysis.md exactly.

What I checked

  • includes/class-opentrust-io.php:631 (wp-admin/includes/media.php) — removed. Confirmed via git grep that no media.php symbol (media_handle_sideload, media_sideload_image, wp_read_image_metadata, wp_read_audio_metadata, wp_handle_sideload, wp_handle_upload) is called anywhere in sideload_bundled_media() or the rest of the plugin. The only post-removal hit for wp_handle_sideload is in the explanatory comment at class-opentrust-io.php:657, which is correct context.
  • includes/class-opentrust-io.php:630 (file.php) — retained. wp_unique_filename() is called at line 666 inside the same method, satisfying the reviewer's "use a function from that file immediately after" carve-out.
  • includes/class-opentrust-io.php:631 (image.php, post-rebase) — retained. wp_generate_attachment_metadata() is called at line 695, same method. Not flagged by the reviewer; correctly left alone.
  • includes/class-opentrust-chat-log.php:44 (upgrade.php) — retained. dbDelta() at line 69, same function. Not flagged; correctly not touched. No need to volunteer changes here.
  • Requires sit inside the function that uses them, not at file top — frontend requests pay nothing.
  • No function_exists() wrappers needed: require_once is idempotent and the consumed symbols (wp_unique_filename, wp_generate_attachment_metadata, dbDelta) are guaranteed once their parent file is loaded.
  • No autoloading hacks, no new globals.
  • POT regeneration (languages/opentrust.pot) is just line-number drift for the four __() strings in the modified method — purely mechanical, correctly included.
  • Import path still works: wp_unique_filename, wp_insert_attachment, wp_generate_attachment_metadata, wp_update_attachment_metadata all remain available via file.php + image.php + core. Direct file_put_contents write preserves the documented SVG carve-out.

Optional nit (non-blocking)

A one-line comment above the remaining requires noting why they stay (the wp_unique_filename / wp_generate_attachment_metadata contract) would inoculate against a future contributor "tidying" them away and re-triggering the reviewer flag. Not required for merge.

— Claude (automated review on behalf of @nolderoos)

@nolderoos
nolderoos merged commit 7633663 into main May 14, 2026
10 checks passed
@nolderoos
nolderoos deleted the fix/core-loading-files branch May 14, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop unused wp-admin/includes/media.php require in IO importer

1 participant